﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NhanSu.aspx.cs" Inherits="Viewer.NhanSu.NhanSu" %>

<%@ Register Src="~/NhanSu/UserControl/UCNhanVien.ascx" TagName="UCNhanVien" TagPrefix="uc" %>
<%@ Register Src="~/NhanSu/UserControl/UCThayDoiCoQuanSuDung.ascx" TagName="UCThayDoiCoQuanSuDung"
    TagPrefix="uc" %>
<%@ Register Src="~/ToChuc/UserControl/UCLookUpDiaChi.ascx" TagName="UCLookUpDiaChi"
    TagPrefix="uc" %>
<%@ Register Src="~/NhanSu/UserControl/UcToChuc.ascx" TagName="UcToChuc" TagPrefix="uc" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <style type="text/css">
        body
        {
            color: #57585B; /*dark gray*/
            font-size: 12px;
            font-family: Arial;
        }
    </style>
    <link href="../resources/css/main.css" rel="stylesheet" type="text/css" />
    <title>Untitled Page</title>
    <ext:XScript ID="XScipt1" runat="server">

        <script type="text/javascript">
         
        function ConfirmDeleteNhanVien(id) {
            Ext.MessageBox.confirm('Thông báo', 'Bạn có chắc chắn xóa record này ko?<br/>Dữ liệu liên quan đến nhân viên sẽ được xóa.', function doDel2(btn) {
                if (btn == 'yes') {
                Ext.net.Mask.show();
                    #{DirectMethods}.ShowDialog('Delete',id);
                }
            });
        }
           var filterTree = function(el, e) {
            var tree = TreePanel,
                text = this.getRawValue();

            tree.clearFilter();

            if (Ext.isEmpty(text, false)) {
                return;
            }

            if (e.getKey() === Ext.EventObject.ESC) {
                clearFilter();
            } else {
                var re = new RegExp(".*" + text + ".*", "i");

                tree.filterBy(function(node) {
                    return re.test(node.text);
                });
            }
        };
        var clearFilter = function() {
            var field = TriggerField1,
                tree = TreePanel;

            field.setValue("");
            tree.clearFilter();
            tree.getRootNode().collapseChildNodes(true);
            tree.getRootNode().ensureVisible();
        };

        var refreshTree = function(tree, result) {
            var nodes = eval(result);
            if (nodes.length > 0) {
                tree.initChildren(nodes);
            }
            else {
                tree.getRootNode().removeChildren();
            }
        }
        
          var TreePanel_Click= function(node)
        {
          Ext.net.Mask.show();    

            if(!node.attributes.IsAdd == '0')
            {   
                btnAddNew.enable();
            }
            else 
            {
                btnAddNew.disable();
            }
              X.LoadGrid(node.id,node.text);  
            if(__currentNode.getValue() == node.id)return ;
                __currentNode.setValue(node.id);
              
            LBL_CurrentTreeItem.setText(node.text);
                  
            IsView= node.attributes.IsView == '1'? true : false;
            IsEdit= node.attributes.IsEdit == '1'? true : false;
            IsDelete= node.attributes.IsDelete == '1'? true : false;          
        };
        
        var IsView,IsEdit,IsDelete;
        
        var storeNhanVien_RemoveById= function(id)
        {
            var record = storeNhanVien.getById(id);
            storeNhanVien.remove(record);
        }
        
        var prepareCommand = function (grid, toolbar, rowIndex, record) {
            var firstGrid = toolbar.items.get(0);
            firstGrid.menu.items.items[0].disabled=!IsView;
            firstGrid.menu.items.items[1].disabled=!IsEdit;
            firstGrid.menu.items.items[2].disabled=!IsDelete;
            
             //   firstButton.setDisabled(true);
            
            //you can return false to cancel toolbar for this record
        };       
        </script>

    </ext:XScript>
</head>
<body>
    <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" Locale="vi"  DirectMethodNamespace="X">
          <Listeners>
            <DocumentReady Handler="Ext.net.DirectEvent.timeout = 360000;" />
            <AjaxRequestException Handler="Ext.net.Mask.hide();" />
            <BeforeAjaxRequest Handler="Ext.net.Mask.show();" />
            <AjaxRequestComplete Handler="Ext.net.Mask.hide();" />
        </Listeners>
    </ext:ResourceManager>
    <div>
        <ext:Hidden ID="__currentNode" runat="server">
        </ext:Hidden>
        <ext:Viewport ID="Viewport1" runat="server">
            <Items>
                <ext:BorderLayout ID="BorderLayout1" runat="server">
                    <North >            
                        <ext:Panel ID="PnSearch" runat="server" Border="false" Region="North"   ButtonAlign="Left" Padding="10" Height="45" >
                             <Items>
                                <ext:CompositeField ID="CompositeField1" runat="server" StyleSpec="margin-bottom:3px;">
                                    <Items>
                                        <ext:TextField ID="txtSoHieuCBCC" runat="server" EmptyText="Nhập số hiệu CBCC " Width="150" />
                                        <ext:TextField ID="txtHoTen" runat="server" EmptyText="Nhập họ & tên " Width="150" />
                                        <ext:TextField ID="txtSoCMND" runat="server" EmptyText="Nhập Số CMND " Width="150" />
                                        <ext:DisplayField ID="DisplayField1" runat="server" Width="60px" />
                                        <ext:Button ID="lnlTimKiemNangCao" runat="server" Icon="ZoomIn" IconAlign="Right">
                                        <Listeners>
                                        <Click Handler="Ext.net.Mask.show();"/>
                                        </Listeners>
                                            <DirectEvents>
                                                <Click OnEvent="showPanel">
                                                </Click>
                                            </DirectEvents>
                                        </ext:Button>
                                        <ext:Button ID="Button3" runat="server" Text="Xóa" IconAlign="Right">
                                            <Listeners>
                                                <Click Handler="Ext.net.Mask.show();#{DirectMethods}.ClearData();" />
                                            </Listeners>
                                        </ext:Button>
                                        <ext:Button ID="btnSearch" runat="server" Icon="Zoom" Text="Tìm kiếm" IconAlign="Right">
                                            <DirectEvents>
                                                <Click OnEvent="btnSearch_Click">
                                                </Click>
                                            </DirectEvents>
                                            <Listeners>
                                                <Click Handler=" Ext.net.Mask.show();var a =#{ext-gen46};" />
                                            </Listeners>
                                        </ext:Button>
                                    </Items>
                                </ext:CompositeField>                                     
                                <ext:CompositeField ID="CompositeField2" runat="server" Hidden="true" StyleSpec="margin-bottom:3px;">
                                    <Items>
                                        <ext:Label ID="lbl" runat="server" Text="Số năm công tác" Width="150" />
                                        <ext:ComboBox ID="cbbToanTuCongTac" runat="server" Width="100" EmptyText="Toán tử">
                                            <Items>
                                                <ext:ListItem Text=">" Value="365" />
                                                <ext:ListItem Text="<" Value="730" />
                                                <ext:ListItem Text="=" Value="1095" />
                                            </Items>
                                            <Triggers>
                                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                            </Triggers>
                                            <Listeners>
                                                <Select Handler="this.triggers[0].show();" />
                                                <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                                <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                                            </Listeners>
                                        </ext:ComboBox>
                                        <ext:TextField ID="txtNam" runat="server" Width="50" EmptyText="Năm">
                                        </ext:TextField>
                                        <ext:Checkbox ID="ckbTrangThaiNghiHuu" runat="server" BoxLabel="Hiển thị nhân viện đã nghỉ hưu" />
                                        <ext:Hidden runat="server" ID="hdChoOThuongTruSearchId">
                                        </ext:Hidden>
                                        <ext:Hidden ID="hdNodeId" runat="server">
                                        </ext:Hidden>
                                        <ext:Hidden ID="hdNodeName" runat="server">
                                        </ext:Hidden>
                                    </Items>
                                </ext:CompositeField>
                                <ext:CompositeField runat="server" ID="CompositeField4" Hidden="true" StyleSpec="margin-bottom:3px;">
                                    <Items>
                                        <ext:Label ID="Label1" runat="server" Text="Số năm vào đảng" Width="150" />
                                        <ext:ComboBox ID="cbbToanTuVaoDang" runat="server" Width="100" EmptyText="Toán tử">
                                            <Items>
                                                <ext:ListItem Text=">" Value="365" />
                                                <ext:ListItem Text="<" Value="730" />
                                                <ext:ListItem Text="=" Value="1095" />
                                            </Items>
                                            <Triggers>
                                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                            </Triggers>
                                            <Listeners>
                                                <Select Handler="this.triggers[0].show();" />
                                                <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                                <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                                            </Listeners>
                                        </ext:ComboBox>
                                        <ext:TextField ID="txtNamVaoDang" runat="server" Width="50" EmptyText="Năm">
                                        </ext:TextField>
                                    </Items>
                                </ext:CompositeField>
                                <ext:CompositeField ID="CompositeField3" runat="server">
                                    <Items>
                                        <ext:Hidden ID="hdTimKiemNangCao" runat="server" />
                                    </Items>
                                </ext:CompositeField>
                            </Items>
                        </ext:Panel>
                    </North>
                    <West Split="true" Collapsible="true" MinWidth="150" MaxWidth="250">
                        <ext:TreePanel ID="TreePanel" runat="server" Icon="ChartOrganisation" Title="Tổ chức"
                            Animate="true" AutoScroll="true" Width="150">
                            <Listeners>
                                <Click Handler="TreePanel_Click(node);" />
                            </Listeners>
                            <TopBar>
                                <ext:Toolbar ID="Toolbar1" runat="server">
                                    <Items>
                                        <ext:ToolbarTextItem ID="ToolbarTextItem1" runat="server" Text="Tìm kiếm:"/>
                                        <%--<ext:ToolbarSpacer />--%>
                                        <ext:TriggerField ID="TriggerField1" runat="server" EnableKeyEvents="true" Width="80">
                                            <Triggers>
                                                <ext:FieldTrigger Icon="Clear" />
                                            </Triggers>
                                            <Listeners>
                                                <KeyUp Fn="filterTree" Buffer="250" />
                                                <TriggerClick Handler="clearFilter();" />
                                            </Listeners>
                                        </ext:TriggerField>
                                    </Items>
                                </ext:Toolbar>
                            </TopBar>
                            <BottomBar>
                                <ext:Toolbar ID="ToolBarTreePanel" runat="server">
                                    <Items>
                                        <ext:Label ID="LBL_CurrentTreeItem" runat="server" Text="Tất cả">
                                        </ext:Label>
                                    </Items>
                                </ext:Toolbar>
                            </BottomBar>
                        </ext:TreePanel>
                    </West>                  
                    <Center>
                        <ext:Panel ID="pnl" runat="server" Border="false" Region="Center" Layout="AbsoluteLayout">
                            <Items>                                
                                <ext:GridPanel ID="GridPanel1" runat="server" X="0" Y="0" AnchorHorizontal="100%"
                                    AnchorVertical="100%" TrackMouseOver="true" StripeRows="true">
                                    <ColumnModel ID="ColumnModel1" runat="server">
                                        <Columns>
                                            <ext:CommandColumn Width="40" ColumnID="Command" Locked="true">
                                                <Commands>
                                                    <ext:GridCommand>
                                                        <Menu>
                                                            <Items>
                                                                <ext:MenuCommand Text="Xem chi tiết" CommandName="View" Icon="LayoutHeader" />
                                                                <ext:MenuCommand Text="Sửa" CommandName="Edit" Icon="ApplicationEdit" />
                                                                <ext:MenuCommand Text="Xóa" CommandName="Delete" Icon="Delete" Cls="menuItemTop">
                                                                </ext:MenuCommand>
                                                                <ext:MenuCommand Text="Thay đổi cơ quan sử dụng" CommandName="Change" Icon="ArrowRefresh"
                                                                    Cls="menuItemTop" />
                                                            </Items>
                                                        </Menu>
                                                    </ext:GridCommand>
                                                </Commands>
                                                <PrepareToolbar Fn="prepareCommand" />
                                            </ext:CommandColumn>
                                            <ext:Column Header="Số hiệu CBCC" DataIndex="SoHieu" Width="100" />
                                            <ext:Column Header="Tên" DataIndex="Ten" Resizable="true" Width="150" />
                                            <ext:Column Header="Ngày sinh" DataIndex="NgaySinh" Resizable="true" Width="100" />
                                            <ext:Column Header="Quê quán" DataIndex="QueQuan" Resizable="true" Width="150" />
                                            <ext:Column Header="Nghề nghiệp" DataIndex="NgheNghiep" Resizable="true" Width="150" />
                                            <ext:Column Header="Chức vụ hiện tại" DataIndex="ChucVuHienTai" Resizable="true"
                                                Width="100" />
                                            <ext:Column Header="Tình trạng CT" DataIndex="TinhTrangCongTac" Resizable="true"
                                                Width="100" />
                                            <ext:Column Header="Cơ quan sử dụng" DataIndex="CoQuanQL" Resizable="true" Width="150" />
                                        </Columns>
                                    </ColumnModel>
                                    <SelectionModel>
                                        <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                                    </SelectionModel>
                                    <Listeners>
                                        <Command Handler="if(command=='Change'){Ext.net.Mask.show();#{DirectMethods}.ShowDialog('Change',record.id);}else if(command=='View'){Ext.net.Mask.show();#{DirectMethods}.ShowDialog('View',record.id);} else if(command=='Edit'){Ext.net.Mask.show();#{DirectMethods}.ShowDialog('Edit',record.id);}else if(command=='Delete'){ConfirmDeleteNhanVien(record.id);}" />
                                    </Listeners>
                                    <BottomBar>
                                        <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageIndex="1" PageSize="20"
                                            HideRefresh="true">
                                        </ext:PagingToolbar>
                                    </BottomBar>
                                    <TopBar>
                                        <ext:Toolbar ID="Toolbar" runat="server" LabelAlign="Right">
                                            <Items>
                                                <ext:Button ID="btnAddNew" runat="server" Text="Tạo mới" IconAlign="Left" Icon="Add">
                                                    <Listeners>
                                                        <Click Handler="Ext.net.Mask.show();" />
                                                    </Listeners>
                                                    <DirectEvents>
                                                        <Click OnEvent="btnAddNew_Click">
                                                        </Click>
                                                    </DirectEvents>
                                                </ext:Button>
                                            </Items>
                                        </ext:Toolbar>
                                    </TopBar>
                                    <Store>
                                        <ext:Store ID="storeNhanVien" runat="server">
                                            <Reader>
                                                <ext:JsonReader IDProperty="Id">
                                                    <Fields>
                                                        <ext:RecordField Name="SoHieu" />
                                                        <ext:RecordField Name="Id" />
                                                        <ext:RecordField Name="Ten" />
                                                        <ext:RecordField Name="NgaySinh" />
                                                        <ext:RecordField Name="SoCMND" />
                                                        <ext:RecordField Name="QueQuan" />
                                                        <ext:RecordField Name="ChucVuHienTai" />
                                                        <ext:RecordField Name="CoQuanQL" />
                                                        <ext:RecordField Name="TinhTrangCongTac" />
                                                        <ext:RecordField Name="NgheNghiep" />
                                                    </Fields>
                                                </ext:JsonReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                </ext:GridPanel>
                            </Items>
                        </ext:Panel>
                    </Center>
                </ext:BorderLayout>
            </Items>
        </ext:Viewport>
        <uc:UCNhanVien ID="UCNhanVien" runat="server"></uc:UCNhanVien>
    </div>
    <uc:UCLookUpDiaChi ID="UCLookUpDiaChi" runat="server"></uc:UCLookUpDiaChi>
    <uc:UcToChuc ID="UcToChuc" runat="server" />
    <uc:UCThayDoiCoQuanSuDung ID="UCThayDoiCoQuanSuDung" runat="server"></uc:UCThayDoiCoQuanSuDung>
    </form>
</body>
</html>
